package com.sskj.tibi.ui.activity;


import android.text.TextUtils;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.alibaba.android.arouter.launcher.ARouter;
import com.sskj.common.base.App;
import com.sskj.common.rxbus2.RxBus;
import com.sskj.common.util.ClickUtil;
import com.sskj.common.util.ToastUtil;
import com.sskj.lib.RConfig;
import com.sskj.lib.base.BaseActivity;
import com.sskj.tibi.R;
import com.sskj.tibi.R2;
import com.sskj.tibi.bean.CommissionConfigBean;
import com.sskj.tibi.bean.FinanceBean;
import com.sskj.tibi.presenter.CommissionWithdrawActivityPresenter;

import butterknife.BindView;

/**
 * 佣金提现
 */
@Route(path = RConfig.TIBI_COMMISSION_WITHDRAW)
public class CommissionWithdrawActivity extends BaseActivity<CommissionWithdrawActivityPresenter> {
    @BindView(R2.id.tvAvailable)
    TextView tvAvailable;
    @BindView(R2.id.etNum)
    EditText etNum;
    @BindView(R2.id.tvAll)
    TextView tvAll;
    @BindView(R2.id.etPwd)
    EditText etPwd;
    @BindView(R2.id.btSubmit)
    Button btSubmit;


    @Override
    protected int getLayoutId() {
        return R.layout.tibi_activity_commission_withdraw;
    }

    @Override
    public CommissionWithdrawActivityPresenter getPresenter() {
        return new CommissionWithdrawActivityPresenter();
    }

    @Override
    protected void initView() {
        ARouter.getInstance().inject(this);
        RxBus.getDefault().register(this);
        setTitle(App.INSTANCE.getString(R.string.tibiwithdrawActivity78));
        ClickUtil.click(btSubmit, () -> {
            if (checkParam()) {

                mPresenter.withdraw(etNum.getText().toString(), etPwd.getText().toString());
            }
        });

    }

    private boolean checkParam() {


        if (TextUtils.isEmpty(etNum.getText())) {
            ToastUtil.showShort(App.INSTANCE.getString(R.string.tibiwithdrawActivity6));
            return false;
        }
        if (TextUtils.isEmpty(etPwd.getText())) {
            ToastUtil.showShort(App.INSTANCE.getString(R.string.tibiwithdrawActivity8));
            return false;
        }
        return true;
    }

    @Override
    protected void initData() {
        mPresenter.getData();
        mPresenter.apiUserAssetinfo();
    }

    public void updateUI(CommissionConfigBean data) {
        etNum.setHint(String.format(App.INSTANCE.getString(R.string.tibiwithdrawActivity3), data.getWithdraw_min()));

    }

    public void withdrawSuccess() {
        finish();
    }

    public void updateMoney(FinanceBean data) {
        ClickUtil.click(tvAll, () -> {
            etNum.setText(data.getFee());
        });
        tvAvailable.setText(String.format(App.INSTANCE.getString(R.string.tibiwithdrawActivity2), data.getFee()));

    }
}
